package com.shadow.bus.main.work;

import android.app.Activity;
import android.app.Dialog;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.shadow.bus.config.PersistData;
import com.shadow.bus.entity.OperationEntity;

import busfix.tepth.com.shadow_bus.R;


/**
 * Created by zhangyu on 2017/3/21.
 */

public class ChooseOperatorDialog extends Dialog {

    public ChooseOperatorDialog(@NonNull final Activity context,final OnOperationChooseListener listener) {
        super(context);
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_choose_actions, null);
        ListView listView = (ListView) view.findViewById(R.id.list_view);
        ArrayAdapter<OperationEntity> adapter = new ArrayAdapter<OperationEntity>(context,
                R.layout.item_text, PersistData.getInstance().getOperationEntities());
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listener != null) {
                    listener.onChoose(PersistData.getInstance().getOperationEntities().get(position));
                }
                dismiss();
            }
        });
        setContentView(view);
    }

    public interface OnOperationChooseListener {
        void onChoose(OperationEntity operationEntity);
    }

}
